#!/bin/sh

CDN_BASE="http://gitee.com/xiahuo/K2-apps/raw/master/K2_apps"
WORK_DIR="/tmp"


logging()
{
    logger -t "[apps]" "$1"
}


wget_install()
{
    [ -x $1 ] && return
	wget --no-check-certificate -q -T 10 -O $1 $2 2>&1 > /dev/null
    [ $? -ne 0 ] && return
	chmod +x $1
}


wget_check()
{
	wget_install $1 $2
    while [ ! -x $1 ]; do
        logging "download \"$1\" failed"
        sleep 10
        rm -rf $1
        wget_install $1 $2
    done
    logging "download \"$1\" successful"
}


do_start()
{
    sh_17ce=$WORK_DIR/17ce_daemon
    wget_check $sh_17ce $CDN_BASE/17ce/17ce_daemon.sh
    logging "start \"$sh_17ce\""
    $sh_17ce ckmx@qq.com &
}


do_start
exit 0
